﻿CREATE PROCEDURE [dbo].[yaf_forum_moderatelist]
AS
    BEGIN
        SELECT   CategoryID = a.CategoryID,
                 CategoryName = a.Name,
                 ForumID = b.ForumID,
                 ForumName = b.Name,
                 MessageCount = COUNT(d.MessageID)
        FROM     yaf_Category a,
                 yaf_Forum b,
                 yaf_Topic c,
                 yaf_Message d
        WHERE    b.CategoryID = a.CategoryID
        AND c.ForumID = b.ForumID
        AND d.TopicID = c.TopicID
        AND (d.Flags & 16) = 0
        AND (c.Flags & 8) = 0
        AND (d.Flags & 8) = 0
        GROUP BY a.CategoryID,a.Name,a.SortOrder,b.ForumID,
                 b.Name,b.SortOrder
        ORDER BY a.SortOrder,
                 b.SortOrder
    END


